#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<long long> tree[N];
long long a[N];
long long ans = 0;
void dfs(int x) {
  for (auto son : tree[x]) {
    dfs(son);
    ans += abs(a[son] - a[x]);
  }
}

int main() {
  int n;
  cin >> n;

  for (int i = 2; i <= n; ++i) {
    int t;
    cin >> t;
    tree[t].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  dfs(1);
  ans += abs(a[1]);
  cout << ans << endl;

  return 0;
}